package leetcode;

import java.util.List;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-19 00:01
 **/
public class LeetCode997 {

    public int findJudge(int n, int[][] trust) {
        //入度表
        int[] inDeg = new int[n + 1];
        //出度表
        int[] outDeg = new int[n + 1];

        for (int[] arr : trust) {
            ++inDeg[arr[1]];
            ++outDeg[arr[0]];
        }

        for (int i = 1; i < n + 1; i++) {
            //如果某一个编号出度为0,即不信任任何人,且入度为n-1,即所有的人都信任他,则此人就是秘密法官
            if (outDeg[i] == 0 && inDeg[i] == n - 1) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        LeetCode997 code = new LeetCode997();
        code.findJudge(2, new int[][]{{1,2}});
    }

}
